#ifndef __INC_QG_TEXMOTION_H__
#define __INC_QG_TEXMOTION_H__

#if _MSC_VER
#pragma once
#endif

//
class qgSubTextureMotion : public qgITextureMotion
{
public:
	typedef tpl::Array<kuintptr>	UintPtrArray;

protected:
	kStream*		_mt_stm;
	qgTexture*		_mt_tex;

	kuint			_mt_totallen;

	kuint			_mt_count;
	kuint			_mt_fps : 16;
	kuint			_mt_bpp : 16;

	float			_mt_fvs;
	float			_mt_len;
	float			_mt_adv;
	float			_mt_fixlen;
	kuint			_mt_index;
	kuint			_mt_next;

	bool			_mt_loop;
	bool			_mt_pause;
	tpl::Point		_mt_range;

	kint*			_mt_sizes;
	kint*			_mt_locations;
	kbyte*			_mt_readdata;
	qgImage*		_mt_ucmimage;

	UintPtrArray	_mt_preimgs;

protected:
	qgSubTextureMotion() {};
	K_VPL ~qgSubTextureMotion() {};

protected:
	void CleanStreams();

	bool ParseMotion(kStream* stm, bool preload);
	bool UpdateStreamImage(kuint image);
	bool UpdateImage(kuint image);
	bool UpdateImage();
	bool UpdateAdvance(float adv);
	void ResetLoop();

public:
	K_OVR kint GetCount() { return _mt_count; }
	K_OVR kint GetFps() { return _mt_fps; }
	K_OVR kint GetIndex() { return _mt_index; }
	K_OVR float GetLength() { return _mt_len; }
	K_OVR float GetAdvance() { return _mt_adv; }
	K_OVR bool IsLoop() { return _mt_loop; }
	K_OVR bool IsPlay() { return _mt_pause ? false : _mt_loop ? true : _mt_adv < _mt_len; }

	K_OVR void Reset();
	K_OVR void SetFixedLength(float len);
	K_OVR void SetFps(kint v);
	K_OVR void SetFrameRange(kint min, kint max);
	K_OVR void SetPosition(float pos);
	K_OVR void SetPlayMode(bool isplay);
	K_OVR void TurnLoop(bool isloop);

	K_OVR bool ManualUpdate(float adv, bool& res, kuintptr& ptr);
	K_OVR qgImage* MotionImage(kint index = -1);
};

#endif	// __INC_QG_TEXMOTION_H__
